home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / datecls.exe / MEMTST.CPP < prev   
Text File  |  1993-03-07  |  7KB  |  196 lines

  1.  
  2.  
  3. #include <iostream.h>
  4.  
  5. #include <stdio.h>
  6. #include <malloc.h>
  7.  
  8. #include "datecls4.h"
  9.  
  10. extern "C" void _setargv() {}
  11. extern "C" void _setenvp() {}
  12.  
  13. void    TestCall(void)
  14. {
  15.     cout << " Date Class v4.0 Demo \n\n";
  16.  
  17.     // Various versions of the constructors
  18.     // and various output
  19.  
  20.     Date x(10,20,1962);
  21.     cout << x.formatDate(FULL) << "\n";
  22.  
  23.     // constuctor with a string, just printing the day of the week
  24.     Date y="8/8/1988";
  25.     cout << y.formatDate(DAY) << "\n";
  26.  
  27.     // constructor with a julian
  28.     Date z( 2450000L );
  29.     cout << z.formatDate(FULL) << '\n';
  30.  
  31.     // using date addition and subtraction
  32.     Date a = x + 10;
  33.     cout << a.formatDate(FULL) << '\n';
  34.     a = a - 25;
  35.     cout << a.formatDate(EUROPEAN) << '\n';
  36.  
  37.     //using subtraction of two date objects
  38.     Date a1 = "7/13/1991";
  39.     Date a2 = a1 + 14;
  40.     cout << (a1-a2) << "\n";
  41.     cout << (a2+=10) << "\n";
  42.  
  43.     a1++;
  44.     cout << "Tommorrow= " << a1.formatDate(FULL) << "\n";
  45.  
  46.     cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < "08/01/1991") ? "TRUE" : "FALSE") << "\n";
  47.     cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > "08/01/1991") ? "TRUE" : "FALSE") << "\n";
  48.     cout << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==(Date)"07/14/1991") ? "TRUE" : "FALSE") << "\n";
  49.     Date a3 = a1;
  50.     cout << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
  51.     Date a4 = a1;
  52.     cout << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
  53.  
  54.     Date a5 = "today";
  55.     cout << "Today is: " << a5 << "\n";
  56.     a4 = "Today";
  57.     cout << "Today (a4) is: " << a4 << "\n";
  58.  
  59.     cout << "Today + 4 is: " << (a4+=4) << "\n";
  60.     a4 = "TODAY";
  61.     cout << "Today - 4 is: " << (a4-=4) << "\n";
  62.  
  63.     cout << "=========== Leap Year Test ===========\n";
  64.     a1 = "1/15/1992";
  65.     cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  66.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  67.  
  68.     a1 = "2/16/1993";
  69.     cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  70.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  71.  
  72.     _dosdate_t b0 = {15,02,1991,1};
  73.     Date b1 = b0;
  74.     cout << "=========== eom test ==============\n";
  75.     cout << "b1.eom() (s/b 2/28/91) ==> " << b1.eom() << "\n";
  76.  
  77.     cout << "================== getDate test =====================\n";
  78.     _dosdate_t ds = a1.getDate();
  79.     cout << "a1.getDate()  (s/b 2/16/1993) ==> " << ds << "\n";
  80.  
  81.     cout << "================== string assignment test ====================\n";
  82.     char *date_string=a1;
  83.     cout << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
  84.  
  85.     cout << "================== setFormat test ============================\n";
  86.     Date::setFormat(FULL);
  87.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  88.     Date::setFormat(EUROPEAN);
  89.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  90.  
  91.     cout << "================== setOption test ============================\n";
  92.     cout << "Date abbreviation ON\n";
  93.     Date::setOption(DATE_ABBR);
  94.     Date::setFormat(MONTH);
  95.     cout << "a1 (s/b MONTH format) ==> " << a1 << "\n";
  96.     Date::setFormat(DAY);
  97.     cout << "a1 (s/b DAY format) ==> " << a1 << "\n";
  98.     Date::setFormat(FULL);
  99.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  100.     Date::setFormat(EUROPEAN);
  101.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  102.     cout << "Century suppression ON\n";
  103.     Date::setOption(NO_CENTURY);
  104.     Date::setFormat(MDY);
  105.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  106.     cout << "Century suppression OFF\n";
  107.     Date::setOption(NO_CENTURY,OFF);
  108.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  109.     cout << "Century suppression ON\n";
  110.     Date::setOption(NO_CENTURY);
  111.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  112.     Date::setFormat(FULL);
  113.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  114.     Date::setOption(DATE_ABBR,OFF);
  115.  
  116.     cout << "\n=============== Version 4.0 Enhancement Test =================\n";
  117.     
  118.     Date v4("11/26/1966");
  119.     cout << "\n---------- Set Stuff -----------\n";
  120.     cout << "First, 'Set' to today..." << "\n";
  121.     cout << "Before 'Set' => " << v4 << "\n";
  122.     cout << "After  'Set' => " << v4.Set() << "\n\n";
  123.  
  124.     cout << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
  125.     cout << "Current Julian  => " << v4.julDate() << "\n";
  126.     cout << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
  127.     cout << "See! => " << v4.julDate() << "\n";
  128.  
  129.     cout << "---------- Add Stuff -----------\n";
  130.     cout << "Start => " << v4 << "\n";
  131.     cout << "Add 4 Weeks => " << v4.AddWeeks(4) << "\n";
  132.     cout << "Sub 1 Month => " << v4.AddMonths(-1) << "\n";
  133.     cout << "Add 2 Years => " << v4.AddYears(2) << "\n";
  134.  
  135.     cout << "---------- Misc Stuff -----------\n";
  136.     cout << "The date aboves' day of the month is => " << v4.Day() << "\n";
  137.     cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
  138.     cout << "The first day of this month lands on " << v4.FirstDOM() << "\n";
  139.     cout << "This day happens to be " << v4.CDOW() << "\n";
  140.     cout << "the " << v4.NDOW() << " day of the week," << "\n";
  141.     cout << "on the " << v4.WOY() << " week of the year," << "\n";
  142.     cout << "on the " << v4.WOM() << " week of the month, " << "\n";
  143.     cout << "(which is " << v4.CMonth() << ")\n";
  144.     cout << "the "<< v4.NMonth() << "nth month in the year.\n";
  145.     cout << "The year alone is " << v4.NYear4() << "\n";
  146.  
  147.     cout << "---------- First and Last Stuff -----------\n";
  148.     v4.Set();
  149.     cout << "The first date of this month is " << v4.BOM() << "\n";
  150.     cout << "The last date of this month is " << v4.EOM() << "\n";
  151.     cout << "The first date of this year is " << v4.BOY() << "\n";
  152.     cout << "The last date of this year is " << v4.EOY() << "\n";
  153.  
  154. }
  155.  
  156.  
  157.  
  158. void    main(void)
  159. {
  160.  
  161.     cout << "Testing for memory leaks in the 'DATECL4' library" << '\n' << flush;
  162.     cout << "Memory before program init " << _memavl() << '\n' << flush;
  163.  
  164.     //printf("Memory before call %u\n", _memavl());
  165.     cout << "Memory before call " << _memavl() << '\n' << flush;
  166.  
  167.     //char    *BufferPtr = new char[500];
  168.  
  169.     //Date    MyDate();
  170.  
  171.     //CMemoryState    OldMemoryState, NewMemoryState, DiffMemoryState;
  172.  
  173.     //OldMemoryState.Checkpoint();
  174.  
  175.     //cout << "Before" << '\n' << flush;
  176.     TestCall();
  177.     //cout << "After" << '\n' << flush;
  178.  
  179.     //NewMemoryState.Checkpoint();
  180.  
  181.     //if (DiffMemoryState.Difference(OldMemoryState, NewMemoryState))
  182.     //{
  183.         //cout << "Memory leak detected!" << '\n' << flush;
  184.         //DiffMemoryState.DumpStatistics();
  185.     //}
  186.  
  187.     //printf("Memory after call %u\n", _memavl());
  188.     cout << "Memory after call " << _memavl() << '\n' << flush;
  189.  
  190.     //delete    [] BufferPtr;
  191.  
  192.     //printf("Memory after call %u\n", _memavl());
  193.     //cout << "Memory after call " << _memavl() << '\n' << flush;
  194.  
  195. }
  196.